package com.example.linyiquan.login.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;

import com.example.linyiquan.login.R;

/**
 * Created by linyiquan on 17-4-13.
 */

public class Welcome extends Activity {

    private boolean isfirst=false;

    private static final int TIME=2000;
    private static final int GO_HOME=1000;
    private static final int GO_GUIDE=1001;

    private Handler handler = new Handler(){

        public void handleMessage(android.os.Message msg){
            switch (msg.what){
                case GO_HOME:
                    goHome();
                    break;
                case GO_GUIDE:
                    goGuide();
                    break;
            }
        };

    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);

        init();
    }

    private void init(){
        SharedPreferences sharedPreferences=getSharedPreferences("data",MODE_PRIVATE);
        isfirst=sharedPreferences.getBoolean("isfirst",true);
        if(!isfirst){
            handler.sendEmptyMessageDelayed(GO_HOME,TIME);
        }else {
            handler.sendEmptyMessageDelayed(GO_GUIDE,TIME);
            SharedPreferences.Editor editor=sharedPreferences.edit();
            editor.putBoolean("isfirst",false);
            editor.commit();
        }
    }

    private void goHome(){
        Intent intent=new Intent(Welcome.this,LoginActivity.class);
        startActivity(intent);
        finish();
    }

    private void goGuide(){
        Intent intent=new Intent(Welcome.this,GuideActivity.class);
        startActivity(intent);
        finish();
    }

}
